<template>


  <el-button size="default" type="default" @click="backToList()">返回</el-button>
  <el-button size="default" type="default" @click="getDetail()">获取数据</el-button>

    <el-descriptions column="3">
        <el-descriptions-item label="id：">{{ dataDetail.id }}</el-descriptions-item>
        <el-descriptions-item label="标题：">{{ dataDetail.title }}</el-descriptions-item>
        <el-descriptions-item label="类型：">{{ typeMap.get(dataDetail.type) }}</el-descriptions-item>
        <el-descriptions-item label="状态：">{{ statusMap.get(dataDetail.status) }}</el-descriptions-item>
        <el-descriptions-item label="驳回原因：" v-if="dataDetail.status === 3">{{ dataDetail.backReason }}</el-descriptions-item>
        <el-descriptions-item label="发布时间：">{{ dataDetail.gmtCreateTime }}</el-descriptions-item>
    </el-descriptions>

    <el-descriptions column="1">
        <el-descriptions-item label="正文内容：">{{ dataDetail.content }}</el-descriptions-item>
    </el-descriptions>

    <el-form-item>
        <el-button type="primary" @click="changeSt('2')">
            审核通过
        </el-button>
        <el-button type="danger" @click="changeSt('3')">
            驳回
        </el-button>
        <el-button type="danger" @click="changeSt('4')">
            屏蔽
        </el-button>
    </el-form-item>


</template>

<script setup>

import { ref } from 'vue'
import {changeStatus, getPostList} from "@/api/request";
import {useRoute, useRouter} from "vue-router";
import {ElMessage} from "element-plus";

const loginUserId = ref("")
const loginUserName = ref("")
const router = useRouter()
const route = useRoute()

const typeMap = ref(new Map([
    ['1', "求助"],
    ['2', "教程"],
    ['3', "讨论"],
    ['4', "分享"],
    ['5', "其他"]
]))
const statusMap = ref(new Map([
    ['0', "未提交"],
    ['1', "待审核"],
    ['2', "已发布"],
    ['3', "被驳回"],
    ['4', "已屏蔽"]
]))


async function changeSt(statusId) {
    let resp = await changeStatus({
        id: route.params.id,
        status: statusId
    }, "/post/update")
    if (resp.code === 200) {
        ElMessage.success("更新成功")
        await getDetail()
    }else {
        ElMessage.error("更新失败")
    }
}

async function getDetail() {
  let tags = await getPostList({
    type: "4"
  }, "/tag/listByType")
  tagList.value = tags.data

    let resp = await getPostList({
        // id: id.values()
        id: route.params.id
    }, "/post/detail")
    console.log(resp)
    dataDetail.value = resp.data
}

const reqParam = ref({
    loginUserId: "",
    loginUserName: "",
    creatorId: "",
    creatorName: "",
    gmtCreateTime: "",
    modifierId: "",
    modifierName: "",
    gmtModifyTime: "",
    id: "",
    title: "",
    type: "",
    content: "",
    tagIds: "",
    tagIdList: [],
    fileUrls: "",
    fileUrlList: [],
    status: "",
    backReason: "",
    saveType: ""
})

const dataDetail = ref({
    // creatorId: "1",
    // creatorName: "无敌战神",
    // gmtCreateTime: "2013-01-02",
    // modifierId: "",
    // modifierName: "",
    // gmtModifyTime: "",
    // id: "1",
    // title: "标题标题",
    // type: "1",
    // content: "正文正文",
    // tagIds: "",
    // tagIdList: [
    //     {
    //         id: "1",
    //         name: "阴阳师",
    //         type: "1",
    //         hotCount: 0,
    //         creatorId: "",
    //         creatorName: "",
    //         gmtCreateTime: "",
    //         modifierId: "",
    //         modifierName: "",
    //         gmtModifyTime: ""
    //     }
    // ],
    // fileUrls: "",
    // fileUrlList: [],
    // status: "2",
    // backReason: "被驳回",
})

const tagList = ref([
    // {
    //     id: "1",
    //     name: "阴阳师",
    //     type: "1",
    //     hotCount: 0,
    //     creatorId: "",
    //     creatorName: "",
    //     gmtCreateTime: "",
    //     modifierId: "",
    //     modifierName: "",
    //     gmtModifyTime: ""
    // },
    // {
    //     id: "2",
    //     name: "只狼",
    //     type: "1",
    //     hotCount: 0,
    //     creatorId: "",
    //     creatorName: "",
    //     gmtCreateTime: "",
    //     modifierId: "",
    //     modifierName: "",
    //     gmtModifyTime: ""
    // },
    // {
    //     id: "3",
    //     name: "美妆",
    //     type: "2",
    //     hotCount: 0,
    //     creatorId: "",
    //     creatorName: "",
    //     gmtCreateTime: "",
    //     modifierId: "",
    //     modifierName: "",
    //     gmtModifyTime: ""
    // }
])

function backToList() {
  router.back()
}

function wait() {
  ElMessage.info("功能开发中，敬请期待....")
}

</script>


<style scoped>

</style>